home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / deliver / ch_poll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  4.7 KB  |  163 lines

  1. /*
  2.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  3.  *     
  4.  *
  5.  *     Copyright (C) 1979,1980,1981  University of Delaware
  6.  *     
  7.  *     Department of Electrical Engineering
  8.  *     University of Delaware
  9.  *     Newark, Delaware  19711
  10.  *
  11.  *     Phone:  (302) 738-1163
  12.  *     
  13.  *     
  14.  *     This program module was developed as part of the University
  15.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  16.  *     
  17.  *     Acquisition, use, and distribution of this module and its listings
  18.  *     are subject restricted to the terms of a license agreement.
  19.  *     Documents describing systems using this module must cite its source.
  20.  *
  21.  *     The above statements must be retained with all copies of this
  22.  *     program and may not be removed without the consent of the
  23.  *     University of Delaware.
  24.  *     
  25.  *
  26.  *     version  -1    David H. Crocker    March   1979
  27.  *     version   0    David H. Crocker    April   1980
  28.  *     version  v7    David H. Crocker    May     1981
  29.  *     version   1    David H. Crocker    October 1981
  30.  *
  31.  */
  32. /* do any polling for mail to pickup                                    */
  33.  
  34. /*    Apr 82  Steve Bellovin    tbldfldir -> logdfldir, for timings files 
  35.  */
  36.  
  37. #include "util.h"
  38. #include "mmdf.h"
  39. #include "ch.h"
  40. #include <sys/stat.h>
  41. #include "nexec.h"
  42. #include "phs.h"
  43.  
  44. extern struct ll_struct *logptr;
  45. extern char *logdfldir;
  46. extern char *chndfldir;
  47. extern int *regfdary;
  48. extern int numfds;
  49.  
  50. LOCFUN pol_chk(), pol_doit();
  51.  
  52. ch_poll (checklist)               /* poll hosts for pickup mail         */
  53.     Chan *checklist[];            /* chans which may be processed       */
  54. {
  55.     extern time_t time ();
  56.     time_t  thetime;              /* current time                       */
  57.     register Chan **chanptr;
  58.  
  59. #ifdef DEBUG
  60.     ll_log (logptr, LLOGPTR, "ch_poll");
  61. #endif
  62.  
  63.     time (&thetime);
  64.     thetime = thetime / (time_t) 900;
  65.                   /* turn it into quarter-hours         */
  66.     for (chanptr = checklist; *chanptr != 0; chanptr++)
  67.     if ((*chanptr) -> ch_poltime != NOPOLL)
  68.         if (pol_chk (thetime, *chanptr))
  69.         pol_doit (*chanptr);
  70. }
  71. /* */
  72.  
  73. LOCFUN
  74.     pol_chk (ptime, pchan)    /* channel due for polling?           */
  75.     time_t    ptime;
  76.     register Chan *pchan;
  77. {
  78.     long    dstrt,                /* when a delivery was last started   */
  79.         ddone,                /*  "   "     "     "    "  finished  */
  80.         pstrt,                /*  "   " pickup    "    "  started   */
  81.         pdone;                /*  "   "     "     "    "  finished  */
  82.  
  83.     if (pchan -> ch_access & DLVRDID)
  84.     return (FALSE);           /* channel been done, this wakeup     */
  85.     if (! (pchan -> ch_access & CH_PICK))
  86.     return (FALSE);           /* pickup not allowed                 */
  87.     if (pchan -> ch_poltime == (char) NOPOLL)
  88.     return (FALSE);           /* polling not allowed                */
  89.  
  90.     if (pchan -> ch_poltime == (char) ALLPOLL)
  91.     return (TRUE);            /* poll every wakeup                  */
  92.  
  93.     dstrt = phs_get (pchan, PHS_WRSTRT);
  94.     if (dstrt > 0L)
  95.     dstrt /= 900L;
  96.  
  97.     ddone = phs_get (pchan, PHS_WREND);
  98.     if (ddone > 0L)
  99.     ddone /= 900L;
  100.  
  101.     pstrt = phs_get (pchan, PHS_RESTRT);
  102.     if (pstrt > 0L)
  103.     pstrt /= 900L;
  104.  
  105.     pdone = phs_get (pchan, PHS_REEND);
  106.     if (pdone > 0L)
  107.     pdone /= 900L;
  108.  
  109.  
  110. #ifdef DEBUG
  111.     ll_log (logptr, LLOGFTR,
  112.         "%s(%d) did=%o, dstrt=%ld, ddone=%ld, pstrt=%ld, pdone=%ld, cur=%ld",
  113.         pchan -> ch_name, pchan -> ch_poltime,
  114.         pchan -> ch_access&DLVRDID, dstrt, ddone, pstrt, pdone, ptime);
  115. #endif
  116.  
  117.     ptime -= pchan -> ch_poltime;
  118.  
  119.     if (dstrt > ddone)        /* outbound mail still pending        */
  120.     return (FALSE);
  121.     if (pstrt > pdone)          /* inbound mail probably still pending  */
  122.     return (TRUE);
  123.     if (ddone > ptime || pdone > ptime)
  124.     return (FALSE);           /* still within delay window          */
  125.  
  126. #ifdef DEBUG
  127.     ll_log (logptr, LLOGFTR, "performing pickup");
  128. #endif
  129.  
  130.     return (TRUE);
  131. }
  132.  
  133. LOCFUN
  134.     pol_doit (thechan)
  135.     register Chan *thechan;
  136. {
  137.     char temppath[128];
  138.     short tmp;
  139.  
  140.     ll_log (logptr, LLOGGEN, "pickup %s", thechan -> ch_name);
  141.     printx ("forcing pickup of %s... ", thechan -> ch_name);
  142.     fflush (stdout);
  143.  
  144.     regfdary[0] = 0;
  145.     regfdary[1] = 1;
  146.     for (tmp = 2; tmp < numfds; regfdary[tmp++] = CLOSEFD);
  147.  
  148. /*  run the channel program, in polling mode.  collect its return value.
  149.  *  if there is a really serious error, force a logging message, otherwise,
  150.  *  treat it more casually.
  151.  */
  152.     getfpath (thechan -> ch_ppath, chndfldir, temppath);
  153.  
  154.     if ((tmp = nexecl (FRKEXEC, FRKWAIT, regfdary, temppath,
  155.         thechan -> ch_name, (domsg) ? "-w" : "-p", (char *)0)) < OK)
  156.     ll_err (logptr, (rp_gbval (tmp) == RP_BNO) ? LLOGTMP : LLOGBTR,
  157.             "(%s) during %s pickup", rp_valstr (tmp),
  158.             thechan -> ch_name);
  159.  
  160.     printx ("\n");
  161. }
  162.  
  163.